package com.vakitdaraliyor.www.dao;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.vakitdaraliyor.www.entity.Countdown;

@Stateless
public class CountdownDao {

	@PersistenceContext
	private EntityManager entityManager;
	
	public CountdownDao() {
	}

	@SuppressWarnings("unchecked")
	public List<Countdown> hepsiniGetir() {
		return entityManager.createQuery("SELECT i from Countdown i")
				.getResultList();
	}

	public void ekle(Countdown gerisayim) {
		entityManager.persist(gerisayim);
	}

	public void sil(Countdown gerisayim) {
		if (entityManager.contains(gerisayim)) {
			entityManager.remove(gerisayim);
		} else {
			Countdown yenigerisayim = (Countdown) entityManager
					.merge(gerisayim);
			entityManager.remove(yenigerisayim);
		}
	}

	public Countdown gerisayimGuncelle(Countdown gerisayim) {
		entityManager.merge(gerisayim);
		return gerisayim;
	}

	public Countdown gerisayimGetirId(Integer id) {
		return (Countdown) entityManager
				.createQuery("select a from Countdown a where a.id =:id")
				.setParameter("id", id).getSingleResult();
	}

	
}